package com.hall.controller;


import com.hall.pojo.LearningApply;
import com.hall.service.LearningApplyService;
import com.hall.pojo.client.WxPusher;
import com.hall.pojo.client.bean.Message;
import com.hall.pojo.client.bean.Result_s;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


import java.util.HashSet;
import java.util.List;
import java.util.Set;


/*
 * 学术会议*/
@Controller
@RequestMapping("/learning")
public class LearningController {

    @Autowired
    LearningApplyService learningApplyService;

    /**
     * 会务大厅
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/meet", produces = {"application/json;charset=UTF-8"})
    public String list(Model model) {
        List<LearningApply> list1 = learningApplyService.selectLearningTimeWith();
        List<LearningApply> list2 = learningApplyService.selectLearningTimeAgreed();
        List<LearningApply> list3 = learningApplyService.selectLearningTimeFinish();
        model.addAttribute("with", list1);
        model.addAttribute("agreed", list2);
        model.addAttribute("Finish", list3);
        return "learning";
    }

    /**
     * 预约学术会议跳转
     *
     * @return
     */
    @RequestMapping("/updatameet")
    public String updatameet() {
        return "addlearning";
    }

    /**
     * 预约学术会议
     *
     * @param learningApply
     * @return
     */
    @ResponseBody
    @RequestMapping("/toaddmeet")
    public String toaddmeet(LearningApply learningApply) {
        learningApplyService.insertLearningApply(learningApply);
        return "ok";
    }


    @Value("${wxpusher.biz.apptoken}")
    private String appToken;

    private String sign = "本消息来自群爱后台系统提醒 http://gaiwo.belovedlive.com:8095/qunai";



    /**
     * 发送普通文本
     */
    @ResponseBody
    @PostMapping("/text/{uids}")
    public Result_s sendText(@PathVariable("uids") Set<String> uids) {

        uids = new HashSet<>();
        uids.add("UID_GXADic6zTb8OkG0n38bmyzhBrgQP");//大超
        uids.add("UID_bCy7gk54RRwzy6E3TVsKBFjJi88t");//杰杰
        uids.add("UID_U3pWitQ1iSO2grVMEO4WTmVY8jvm");//王哥
        uids.add("UID_2yxmRcGEpue7h6pkNkDK8wR2yxlF");//吕老师

        Message message = new Message();
        message.setContentType(Message.CONTENT_TYPE_TEXT);
        message.setUids(uids);
        message.setAppToken("AT_QWT5OPzfRZORbLPbNGPnz5yAYO6H9ohL");
        message.setContent("有人申请了新的学术会议，请您尽快处理\n\n\n" + sign);
        message.setUrl("http://gaiwo.belovedlive.com:8095/qunai");

        return WxPusher.send(message);
    }


    /**
     * 查询预约结果
     *
     * @param tell
     * @param phone
     * @return
     */
    @RequestMapping(value = "/selectmeet", produces = {"application/json;charset=UTF-8"})
    public String selectmeet(Model tell, String phone) {
        List<LearningApply> s = learningApplyService.selectResult();//返回查询当前输入的手机号对应的result
        tell.addAttribute("phone1", s);
        return "select_learning";
    }

    @GetMapping("/ready")
    public String learningReady() {
        return "learning_ready";
    }

    @GetMapping("/past")
    public String learningPast() {
        return "learning_past";
    }

    @GetMapping("/live")
    public String learnintLive() {
        return "learning_live";
    }

}
